/* iterLib.h - demand-sorted table library header file*/

/* Copyright 2003-2005 Neotune Information Technology Co., Ltd. */

#ifndef __INCiterLibh
#define __INCiterLibh

#ifdef __cplusplus
extern "C" {
#endif

#include "neos_vx_win.h"


/* status codes */
#define S_iterLib_INVALID_ID             (M_iterLib | 1)
#define S_iterLib_INVALID_HEADER         (M_iterLib | 2)
#define S_iterLib_INVALID_FIRSTFN        (M_iterLib | 3)
#define S_iterLib_INVALID_NEXTFN        (M_iterLib | 4)
#define S_iterLib_ALLOC_ERROR            (M_iterLib | 5)
#define S_iterLib_INVALID_DIRECTION        (M_iterLib | 6)
#define S_iterLib_FORWARD_ONLY             (M_iterLib | 7)
#define S_iterLib_INVALID_MATCHDATA        (M_iterLib | 8)
#define S_iterLib_SORTED_ONLY            (M_iterLib | 9)
#define S_iterLib_INVALID_USERFN        (M_iterLib | 10)
#define S_iterLib_INVALID_STARTLOC        (M_iterLib | 11)

/* type definitions */

/*
* Each iterator-enabled data type must include space for one of these 
* structures at the beginning of the data structure (e.g., at the address
* pointed to by handles of that type).
*/
typedef struct        /* Demand sort table entry trailer */
{
    void *iterCtl;                /* iterator control address */
}   ITER_HEADER;

/*
* Iterator user function type (void).  Entry is at address <entry>, 
* and is in the index list <index>.  <arg1> has the value of the 
* optional argument.  Returns void.
*/
typedef void (*IFVFUNCPTR) ( void *entry, ulong_t index, ulong_t arg1 );

/*
* Iterator user function type (STATUS).  Entry is at address <entry>, 
* and is in the index list <index>.  <arg1> has the value of the 
* optional argument.  Returns STATUS.
*/
typedef STATUS (*IFBFUNCPTR) ( void *entry, ulong_t index, ulong_t arg1 );


#if defined(__STDC__) || defined(__cplusplus)
IMPORT STATUS    iterCreate
    ( 
    ITER_HEADER *header,
    FLFUNCPTR firstFn,
    FLFUNCPTR lastFn,
    NPFUNCPTR nextFn,
    NPFUNCPTR prevFn,
    CMPFUNCPTR compareFn,
    ulong_t  compareArg
    );
IMPORT STATUS    iterDestroy( ITER_HEADER *header );
IMPORT void *iterSearchForEntry
    ( 
    ITER_HEADER *header,             
    ulong_t index,                        
    const void *matchData,            
    void *startLoc,                    
    int matchCondition,                
    ulong_t direction                     
    );
IMPORT STATUS iterForEachEntry
    ( 
    ITER_HEADER *header,                 
    ulong_t index,                        
    IFVFUNCPTR userFn,
    ulong_t argVal,                        
    ulong_t direction                     
    );
IMPORT STATUS iterForEachEntryUntil
    ( 
    ITER_HEADER *header,                 
    ulong_t index,                        
    IFBFUNCPTR userFn,
    ulong_t argVal,                        
    ulong_t direction,                    
    void **startLoc                  
    );
IMPORT STATUS iterForSelectedNodes
    ( 
    ITER_HEADER *header,                 
    ulong_t index,                        
    IFVFUNCPTR userFn,
    ulong_t argVal,                        
    ulong_t direction,                     
    const void *matchData,            
    void **startLoc,                
    int matchCondition                 
    );
IMPORT ulong_t iterGetMemSize( void );
IMPORT STATUS iterForSelectedEntries
    ( 
    ITER_HEADER *header,            /* iterator header address            */
    ulong_t indexVal,               /* index of the list to process       */
    IFVFUNCPTR userFn,              /* list entry processing function     */
    ulong_t argVal,                 /* argument value to pass to userFn   */
    ulong_t direction,              /* 0 for forwards, 1 for reverse      */
    const void *matchData,          /* data to compare against            */
    void **startLoc,                /* entry to begin searching from      */
    int matchCondition              /* <0 for LT, 0 for EQ, 01 for GT     */
    );
#else   /* __STDC__ */
IMPORT STATUS    iterCreate( );
IMPORT STATUS    iterDestroy( );
IMPORT void *iterSearchForEntry( );
IMPORT STATUS iterForEachEntry( );
IMPORT STATUS iterForEachEntryUntil( );
IMPORT STATUS iterForSelectedNodes( );
IMPORT ulong_t iterGetMemSize( );
#endif  /* __STDC__ */

#ifdef __cplusplus
}
#endif

#endif


